import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Line {
	public static void main(String[] args) {
		File file = new File(args[args.length - 1]);
		boolean append = false;
		PrintWriter writer = null;
		try {
			writer = new PrintWriter(new BufferedWriter(new FileWriter(file,
					append)));
			// System.err.println(Arrays.toString(args));
			URL url = new URL(args[0]);
			URLConnection conn = url.openConnection();
			InputStream in = conn.getInputStream();
			BufferedReader read = new BufferedReader(new InputStreamReader(in));
			StringBuffer sb = new StringBuffer();
			String line;
			while ((line = read.readLine()) != null) {
				sb.append(line).append("\r\n");
			}
			// System.out.println(sb);
			Pattern p = Pattern.compile(args[1]);
			Matcher m = p.matcher(sb);
			// System.err.println("start!");
			while (m.find()) {
				// System.err.println(m.group());
				for (int i = 2; i < args.length - 1; i++) {
					if (i > 2)
						writer.print("\t");
					writer.print(m.group(Integer.parseInt(args[i]))
							.replace('\t', ' ').trim());
				}
				writer.println();
				writer.flush();
			}
			// System.err.println("finish!");
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			writer.close();
		}
	}
}
